package cn.iocoder.yudao.module.xiaoBizHandler.demo;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.genCode.common.StringBuilderHandler;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenColumnDO;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenTableDO;

import java.lang.reflect.Field;

public class Demo {

    public static void main(String[] args) {
//        Class<XiaoBizHandlerCodegenColumnDO> aClass = XiaoBizHandlerCodegenColumnDO.class;
//        String template = "s = s.replace(\"${column.%s}\", \"\\\" + column.get%s() + \\\"\");";
//
//        Class<XiaoBizHandlerCodegenColumnDO> aClass = XiaoBizHandlerCodegenColumnDO.class;
//        String template = "s = s.replace(\"${primaryColumn.%s}\", \"\\\" + primaryColumn.get%s() + \\\"\");";
//
        Class<XiaoBizHandlerCodegenTableDO> aClass = XiaoBizHandlerCodegenTableDO.class;
        String template = "s = s.replace(\"${table.%s}\", \"\\\" + table.get%s() + \\\"\");";


        StringBuilderHandler code = gen(aClass, template);
        System.out.println(code.toString());

    }

    private static StringBuilderHandler gen(Class<?> aClass, String template) {
        Field[] fields = aClass.getDeclaredFields();
        StringBuilderHandler code = new StringBuilderHandler();
        for (Field field : fields) {
            String line = String.format(template, field.getName(), StrUtil.upperFirst(field.getName()));
            code.apAndBl(line);
        }
        return code;
    }

}
